/*******************************************************************************
 * Copyright (c) 2012, 2013 XML-Print Project.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     XML-Print Project - initial API and implementation
 ******************************************************************************/
package info.xmlprint;

import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
import org.eclipse.ui.application.WorkbenchWindowAdvisor;

public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {

	public ApplicationWorkbenchWindowAdvisor(
			IWorkbenchWindowConfigurer configurer) {
		super(configurer);
	}

	public ActionBarAdvisor createActionBarAdvisor(
			IActionBarConfigurer configurer) {
		return new ApplicationActionBarAdvisor(configurer);
	}

	public void preWindowOpen() {
		IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
		configurer.setInitialSize(new Point(1024, 768));
		configurer.setShowCoolBar(true);
		configurer.setShowStatusLine(false);
	}

	public void postWindowOpen() {
		IWorkbenchWindowConfigurer configurer = getWindowConfigurer();

		// IWorkbenchWindow[] windows =
		// PlatformUI.getWorkbench().getWorkbenchWindows();
		// for (int i = 0; i < windows.length; ++i) {
		IWorkbenchPage page = configurer.getWindow().getActivePage();
		if (page != null) {
			// hide generic 'File' commands
			// page.hideActionSet("org.eclipse.ui.actionSet.openFiles");

			// hide 'Convert Line Delimiters To...'
			// page.hideActionSet("org.eclipse.ui.edit.text.actionSet.convertLineDelimitersTo");

			// hide 'Search' commands
			page.hideActionSet("org.eclipse.search.searchActionSet");

			// hide 'Annotation' commands
			page.hideActionSet("org.eclipse.ui.edit.text.actionSet.annotationNavigation");

			// hide 'Forward/Back' type navigation commands
			// page.hideActionSet("org.eclipse.ui.edit.text.actionSet.navigation");
		}
		// }

		// IActionBarConfigurer iac = configurer.getActionBarConfigurer();
		// IMenuManager menuManager = iac.getMenuManager();
		// IContributionItem ic;
		// for (String s : new String[] { "org.eclipse.search.menu", "navigate",
		// "org.eclipse.ui.run" }) {
		// ic = menuManager.find(s);
		// if (ic != null) {
		// menuManager.remove(ic);
		// }
		// }
		// menuManager.update(true);

		// ICoolBarManager coolBarMangager = iac.getCoolBarManager();
		// for (String s : new String[] { "org.eclipse.debug.ui.launch.toolbar",
		// "org.eclipse.debug.ui.main.toolbar",
		// "org.eclipse.search.searchActionSet",
		// "org.eclipse.ui.edit.text.actionSet.annotationNavigation",
		// "org.eclipse.ui.edit.text.actionSet.navigation" }) {
		// ic = coolBarMangager.find(s);
		// if (ic != null) {
		// coolBarMangager.remove(ic);
		// }
		// }
		// coolBarMangager.update(true);

		Shell shell = configurer.getWindow().getShell();
		shell.setMaximized(true);
		shell.setMinimumSize(640, 480);

	}
}
